package router

import (
	"oa-system/internal/api/handler"
	"oa-system/internal/api/middleware"
	"oa-system/internal/config"
	"oa-system/internal/database"
	"oa-system/internal/repository"
	"oa-system/internal/service"

	"github.com/gin-gonic/gin"
)

func RegisterDepartmentRoutes(r *gin.Engine) {
	// 初始化依赖
	departmentRepo := repository.NewDepartmentRepository(database.DB)
	departmentService := service.NewDepartmentService(departmentRepo)
	departmentHandler := handler.NewDepartmentHandler(departmentService)

	// API 路由组
	api := r.Group(config.GlobalConfig.App.APIPrefix)

	// 需要认证的路由
	departmentGroup := api.Group("/departments")
	// 开启JWT认证
	departmentGroup.Use(middleware.JWTAuthMiddleware())
	{
		departmentGroup.GET("", departmentHandler.GetAllDepartments)
		departmentGroup.POST("", departmentHandler.CreateDepartment)
		departmentGroup.PUT("/:id", departmentHandler.UpdateDepartment)
		departmentGroup.DELETE("/:id", departmentHandler.DeleteDepartment)
	}
}
